package gentle.controller;

import gentle.config.Permission;
import gentle.base.SqlMapper;
import gentle.entity.Deptinfos;
import gentle.entity.SearchReservationsInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import gentle.service.ITestService;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("gentle")
public class TestController {

    @Autowired
    private SqlMapper sqlMapper;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    ITestService testService;


    @RequestMapping("/first")
    private String first(String name, String word) {
        Long seconds = redisTemplate.opsForValue().getOperations().getExpire("redisKey");
        System.out.println(seconds);
        int tempTime = this.redisTemplate.getExpire("max").intValue();
        this.redisTemplate.expire("max",tempTime, TimeUnit.SECONDS);
        Long seconds1 = redisTemplate.opsForValue().getOperations().getExpire("redisKey");
        System.out.println(tempTime);
        return name + "，这是一个名字。 " + word + "这是一句描述。";
    }

    //查询病历
    @RequestMapping(value = "/getCaseData", method = RequestMethod.POST)
    @ResponseBody
    public String getArchivings(String id) throws Exception {
        String sql = "select t.id as id , t.simplename,t.fullname,t.abbreviation,t.proportional as proportional,t.level_one_audit as levelOneAudit,t.level_two_audit as levelTwoAudit," +
                "t.province,t.lowest_price_bill as lowestPriceBill,t.cities,t.address,t.member_switch as memberSwitch,t.phone,t.auditswitch,t.auditOfDept,t.area_abbreviation as areaAbbreviation,t.version as version," +
                "t.subordinate_abbreviation as subordinateAbbreviation,CONCAT(sttle_accounts_hour,':',sttle_accounts_minute,':',sttle_accounts_second) as sttleAccountsHour " +
                " from dept t where t.simplename= '国贸店' limit 1";
        Deptinfos dept = sqlMapper.selectOne(sql, Deptinfos.class);
        return "，这是一个名字。 这是一句描述。";
    }

    /**
     * 获取所有部门列表
     */
    @RequestMapping(value = "/list")
    @Permission
    @ResponseBody
    public Object list(String condition) {
        List<Map<String, Object>> list = testService.deptDaoList(condition);
        return list;
    }

    @RequestMapping(value = "/getcount", method = RequestMethod.GET)
    @ResponseBody
    public List<Map<String, Object>>  getcount(SearchReservationsInfo info, HttpServletRequest request) {
        String sql = "select * from reservations_info a limit 5000";
        List<Map<String, Object>> List = sqlMapper.selectList(sql);
        return List;
    }
}
